package com.woniu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.pojo.Berth;
import com.woniu.pojo.Road;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.entity.dto.QueryBerthDTO;
import com.woniu.entity.vo.BerthVo;
import com.woniu.pojo.Berth;
import com.woniu.pojo.Road;
import org.apache.ibatis.annotations.Select;

/**
* @author Ma.Lei
* @description 针对表【t_berth】的数据库操作Mapper
* @createDate 2022-12-16 23:27:33
* @Entity generator.domain.Berth
*/
public interface BerthMapper extends BaseMapper<Berth> {

    @Select("SELECT * from t_berth WHERE berth_code = #{berthCode} and berth_type = 0")
    @ResultType(Berth.class)
    Berth selectByBerthCode(String berthCode);

    @Select("SELECT b.id,b.road_name from t_berth a,t_road b\n" +
            "WHERE a.road_id = b.id and a.berth_code=#{berthCode}")
    @ResultType(Road.class)
    Road selectRoadByBerthCode(String berthCode);

    @Update("UPDATE t_berth set berth_type=#{status} WHERE id = #{id}")
    void updateStatusById(String id, String status);
    @Select("select id as berthId from t_berth where berth_code = #{berthCode}")
    String getIdByCode(String berthCode);

    @Update("update t_berth set berth_type = s where id = #{berthId}")
    void updateBerthStatus(String berthId, String s);

    @Select(" select  distinct road_name from t_berth tb inner join t_road tr" +
            " on tb.road_id = tr.id where tr.id = #{id}")
    Road getByRoadName(String id);


    IPage<BerthVo> selectPageberth(IPage<BerthVo> page, QueryBerthDTO queryBerthDTO);
}




